<template>
  <div>
    <el-dialog
      title="修改账户"
      :visible.sync="dialogVisible"
      width="30%"
      :before-close="resetForm"
    >
      <el-form :model="Form" :rules="rules" label-width="80px" ref="changeForm">
        <el-form-item label="姓名" prop="nickName">
          <el-input v-model="Form.nickName" placeholder="请输入姓名"></el-input>
        </el-form-item>
        <el-form-item label="用户名">
          <el-input v-model="Form.userName" disabled></el-input>
        </el-form-item>
        <el-form-item label="号码">
          <el-input v-model="Form.phonenumber" disabled></el-input>
        </el-form-item>
        <el-form-item label="邮箱" prop="email">
          <el-input
            v-model="Form.email"
            placeholder="请输入正确的邮箱地址"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm('changeForm')"
            >修改</el-button
          >
          <el-button @click="resetForm">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
export default {
  props: {
    dialogVisible: {
      type: Boolean,
      default: () => false,
    },
    dialogForm: {
      type: Object,
      default: () => {},
    },
  },

  computed: {
    Form() {
      return this.dialogForm;
    },
  },

  data() {
    return {
      rules: {
        nickName: [
          { required: true, message: "请输入用户姓名", trigger: "blur" },
        ],
        email: [
          {
            pattern: /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/,
            required: true,
            message: "请输入正确的邮箱地址",
            trigger: "blur",
          },
        ],
      },
    };
  },
  created() {},
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$emit("changeUserFun", this.Form);
        }
      });
    },

    resetForm() {
      if (!this.dialogVisible) return;
      this.$refs.changeForm.resetFields();
      this.$emit("closeChangedia");
    },
  },
};
</script>
